package com.loong.game2048.module.vo;

import com.loong.game2048.Exception.BizException;
import com.loong.game2048.module.ResultCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author lyx
 * @date 2020/5/3 16:19
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private Integer code = 200;

    private String msg = "success";

    private String token;

    private T data;

    public Result(String msg, Integer code) {
        this.msg = msg;
        this.code = code;
    }

    public Result(T data) {
        this.data = data;
    }

    public Result(Integer code, T data){
        this.code = code;
        this.data = data;
    }


    /**
     * @Description : 此时系统发生未知异常
     * @Param : [e]
     * @Return :
     */
    public Result(Throwable e) {
        super();
        this.msg = "发生未知错误，请稍后重试!";
        this.code = ResultCode.UNSPECIFIED;
    }

    public Result(BizException e){
        super();
        this.msg = e.getMessage();
        this.code = Integer.valueOf(e.getCode());
    }

}
